rm(list = ls())
library(foreign)
library(readstata13)

d <- read.dta13("Barber_Bolton_Thrower_Replication_Data_LSQ.dta")
d <- subset(d, year > 1992 & year < 2014)

d <- d[d$state_fe != "Nebraska",]
d$house_polarization_impute[d$state_fe == "Kentucky"] <- 0

states <- as.character(unique(d$state_fe))

#First 25 states
par(mfrow = c(5, 5), mar = c(2, 4.1, 1, 2.1))
for(j in 1:25){
  al <- subset(d, state_fe == states[j])
  plot(al$year, al$house_polarization_impute, type = "l", xlab = "Year", ylab = states[j],
       xlim = c(1993, 2013))
  years <- unique(al$year)
}

###################

#Last 25 states
par(mfrow = c(5, 5), mar = c(2, 4.1, 1, 2.1))
for(j in 26:49){
  al <- subset(d, state_fe == states[j])
  plot(al$year, al$house_polarization_impute, type = "l", xlab = "Year", ylab = states[j],
       xlim = c(1993, 2013))
  years <- unique(al$year)
}